package com.chain.BrotherExchange.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.widget.Button;

import com.chain.BrotherExchange.R;
import com.chain.BrotherExchange.event.LogoutEvent;
import com.chain.BrotherExchange.ui.core.BaseActivity;
import com.chain.BrotherExchange.utils.ActivityBarHelper;
import com.chain.BrotherExchange.utils.Androids;

import org.greenrobot.eventbus.EventBus;

import butterknife.Bind;

public class SettingActivity extends BaseActivity {

    @Bind(R.id.logout_button) Button mLogoutButton;

    public static void launch(Context context) {
        context.startActivity(new Intent(context, SettingActivity.class));
    }

    @Override
    protected int getLayoutID() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initActions() {
        ActivityBarHelper.init(this, R.string.title_setting);
        mLogoutButton.setOnClickListener(v -> logout());
    }

    private void logout() {
        new AlertDialog.Builder(this)
                .setMessage(R.string.message_exit_the_app)
                .setPositiveButton(R.string.sure, (dialog, which) -> {
                    Androids.LocalConfig.logout();
                    EventBus.getDefault().post(new LogoutEvent());
                    MainActivity.launch(this);
                }).setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()
        ).show();
    }
}
